package com.thinkgem.jeesite.common.utils;

import java.util.HashMap;
import java.util.Set;

import com.thinkgem.jeesite.common.utils.RLYTXUtils.CCPRestSDK;

public class SendTemplateSMSUtil {

	private static final String uri = "app.cloopen.com";//服务期地址
	private static final String PortNumber= "8883";
	private static final String AccountSid = "aaf98f89512446e2015142550e955874";//主张号
	private static final String AccountToken = "64f9b0968769498aae6df835dea28777";//主帐号TOKEN
	private static final String APPID = "8aaf0708582eefe9015846ffa53810b6";
	
	
	/**
	 * 发送短信
	 * @param tel 电话
	 * @param templateNumber 短信模版ID
	 * @param context 短信内容
	 * @return
	 */
	public static int sendTemplate(String tel,String templateNumber,String[] context){
		HashMap<String, Object> result = null;
		CCPRestSDK restAPI = new CCPRestSDK();
		restAPI.init(uri, PortNumber);
		restAPI.setAccount(AccountSid, AccountToken);
		restAPI.setAppId(APPID);
		
		result = restAPI.sendTemplateSMS(tel, templateNumber,context );
//		System.out.println("SDKTestSendTemplateSMS result=" + result);
//		System.out.println(result.get("statusCode"));
		if("000000".equals(result.get("statusCode"))){
			@SuppressWarnings("unchecked")
			HashMap<String,Object> data = (HashMap<String, Object>) result.get("data");
			Set<String> keySet = data.keySet();
			for(String key:keySet){
				Object object = data.get(key);
//				System.out.println(key +" = "+object);
			}
		}else{
			return -1;
		}
		return 1;
	}
	
	public static void main(String[] args) {
		String[] context = {"123456","60s"};
		int i = sendTemplate("15147244051","131489",context);
//		System.out.println(i);
	}
	
}
